package com.lizhao.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 分为不分组展示和分组展示方案，区别在于，不分组去掉了.groupName(groupName)，而分组方案明确了组，
 * 具体请查看访问地址 http://localhost:9000/swagger-ui.html 右上角的下拉菜单
 * 测试方法：点击控制器->方法->Try it out
 */

@Configuration
@EnableSwagger2

//分组展示方案
/*
public class SwaggerAutoConfiguration {
    @Bean
    public Docket createRestApi1(){
        String title = "User文档";
        String version = "1.0";
        String description = "描述User接口文档";
        String groupName = "用户接口组";
        String basePackage = "com.lizhao.controller.user";


        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(title)
                .version(version)
                .description(description)
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .build();

        return docket;
    }

    @Bean
    public Docket createRestApi2(){
        String title = "Menu接口文档";
        String version = "1.0";
        String description = "描述Menu接口文档";
        String groupName = "菜单接口组";
        String basePackage = "com.lizhao.controller.menu";


        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(title)
                .version(version)
                .description(description)
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .build();

        return docket;
    }
}

 */


//不分组展示方案
public class SwaggerAutoConfiguration {
    @Bean
    public Docket createRestApi(){
        String title = "接口文档";
        String version = "1.0";
        String description = "描述接口文档";
        String basePackage = "com.lizhao.controller";


        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(title)
                .version(version)
                .description(description)
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .build();

        return docket;
    }
}